/*
 * @Author: your name
 * @Date: 2019-11-12 08:30:01
 * @LastEditTime: 2025-01-26 23:01:57
 * @LastEditors: ljkt
 * @Description: In User Settings Edit
 * @FilePath: \Sources\C\SysDeal.h
 */
#ifndef _DEV_KEY_H_
#define _DEV_KEY_H_
#define DEV_KEY_TASK_TIME (10)

#define DEV_KEY_POWER (1 << 0ul)
#define Dev_Key_Type_NewSta() \
	{                         \
		do                    \
		{                     \
		gDev_Key.New_Sta = keys_flag; \
		} while (0);          \
	}

/* 按键口 */
enum KEY_CMD
{
	e_KEY_NO,		   /* 没有按键 */
	e_KEY_DOWN,		   /* 按下 */
	e_KEY_CHANG0_DOWN, /* 长按0 */
	e_KEY_CHANG1_DOWN, /* 长按1 */
	e_KEY_CHANGX_DOWN, /* 连加减 */
	e_KEY_UP,		   /* 上升沿 */
};
#define LOG_KEY_TAB_INIT                   \
	{                                      \
		INDEX_AND_NAME(e_KEY_NO),          \
		INDEX_AND_NAME(e_KEY_DOWN),        \
		INDEX_AND_NAME(e_KEY_CHANG0_DOWN), \
		INDEX_AND_NAME(e_KEY_CHANG1_DOWN), \
		INDEX_AND_NAME(e_KEY_CHANGX_DOWN), \
		INDEX_AND_NAME(e_KEY_UP),          \
	}
#define Read_Key(key, type, val) ((key->Cmd == type) && (key->Val == (val)))
#define Read_Key_Sta(val) (gDev_Key.New_Sta & (val))
#define Read_Key_AllSta() (gDev_Key.New_Sta)
// #define Read_Key_Sta2(val) (gDev_Key.New_Sta & val)

#define KEY_DOWN_SHORT_TIME_CNT (100UL / DEV_KEY_TASK_TIME)
#define KEY_DOWN_LONG0_TIME_CNT (1000UL / DEV_KEY_TASK_TIME)
#define KEY_DOWN_LONG1_TIME_CNT (5000UL / DEV_KEY_TASK_TIME)
// #define KEY_DOWN_LONGX_TIME_CNT (1000UL / DEV_KEY_TASK_TIME)

#ifdef KEY_DOWN_LONGX_TIME_CNT
// #define KEY_DOWN_LONGX_SPEED_CNT (300UL / DEV_KEY_TASK_TIME)
#define KEY_DOWN_LONGX_SPEED_CHANGE
#endif

typedef struct
{
	unsigned char Cmd;
	unsigned long Val;
} s_dev_key_cv_t;
typedef struct
{
	unsigned char EnShortUp;
	unsigned long New_Sta;
	unsigned long Old_Sta;
	unsigned short Downx_Time;
	unsigned short Down_Time;
	s_dev_key_cv_t Type;
} s_dev_key_t;
extern Ram s_dev_key_t gDev_Key;

extern void Dev_Key_Init(void);
extern s_dev_key_cv_t *Dev_Key_Get(unsigned char clr);
extern void Dev_Key_Scan(void);
#endif
